Login Method

Syntax

Context.Security.Login as L (UserName as C, Password as C, RedirectPage as C = null_value(), ClientCookie as L = .F., DaysUntilExpiration as N = 10)

Arguments

UserName as CCharacter

The name of the user.

PasswordCharacter

The password for the user.

RedirectPageCharacter

The page the user will be redirected to on successful login. If not specified the application defined redirect page will be used.

ClientCookieLogical

Set to .T. to create a persistent cookie. This type of cookie will remain across browser sessions. That is, if you close your browser and restart the cookie will be available. When set to .F. the cookie will not be available across browser sessions. The cookie is deleted when close your browser. This is the default and is a more secure setting.

DaysUntilExpirationNumeric

The number of days the authentication cookie is valid. This is calculated from the time of the last request made with the cookie.

Returns

resultLogical

Returns .T. if the user is logged in; otherwise .F.

Description

Logs in a user to a specific page and sets the authentication cookie's lifetime.

Discussion

Context.Security.Login() logs in a user and optionally letting you redirect the successful login to a specific page and set the authentication cookie's lifetime. When login is successful the Context.Security.CallResult.ReturnDataValue will contain the redirect page URL. Check Context.Security.CallResult.Success before using the return value.

Example: Redirecting After Login

Upon successful login, the user can be redirected to another page. The Context.Security.CallResult object has a property called ReturnDataValue that contains the page to redirect the user after login. This property will either contain the default redirect page defined in security settings or contain the redirect page specified when the login method was called. If login fails or the redirect behavior is set to "current page", Context.Security.CallResult.ReturnDataValue will be blank.

The example below demonstrates how to peform a redirect using Context.Security.CallResult.ReturnDataValue:

context.Security.Login(Username,password,"index.a5w")
if context.Security.CallResult.Success
    if Context.Security.CallResult.ReturnDataValue <> ""           ' has a redirect
        response.redirect(Context.Security.CallResult.ReturnDataValue)
    end if
end if

Example: Redirecting After Login with JavaScript

The redirect can also be made using JavaScript (returned by an Ajax Callback):

if Context.Security.CallResult.ReturnDataValue <> ""         ' has a redirect
    javascript = "window.location='"+Context.Security.CallResult.ReturnDataValue+"';"
end if